

#include <Ogre.h>
#include "OgreInterface.h"

using namespace Ogre;


class WindowListener : public FrameListener {
    RenderWindow *window;
public:
    WindowListener( RenderWindow *windowArg );
    bool frameStarted (const FrameEvent &evt);
    bool frameEnded (const FrameEvent &evt);
};




bool OgreInterface::activateWindowListener( ) {

    if (this->window == NULL) return false;

    //Create a frame listener to handle window closing
    FrameListener *windowListener = new WindowListener( this->window );
    //listener->setWindow( window );
    root->addFrameListener( windowListener );

    return true;
}



/**
 *Constructor of the frame listener
 * @window : pointer to the main window of the application
 */
WindowListener::WindowListener( RenderWindow *windowArg ) {
    window = windowArg;
}

/**
 * This method adds events to the render loop that occur
 * before each frame is rendered.
 */
bool WindowListener::frameStarted(const FrameEvent &evt) {

    if(window->isClosed()) return false;

    return true;
}

/**
 * This method adds events to the render loop that occur
 * after each frame is rendered.
 */
bool WindowListener::frameEnded(const FrameEvent &evt) {
    return true;
}
